package com.cyj.dream.auth.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cyj.dream.auth.entity.SysUser;
import com.cyj.dream.core.util.nosql.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;


/**
 * @Description: 身份验证成功的处理程序
 * @BelongsProject: DreamChardonnay
 * @BelongsPackage: com.cyj.dream.auth.handler
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-30 14:19
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@Component
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Autowired
    private RedisUtil redis;

    /**
     * 用户认证成功
     *
     * @param req
     * @param res
     * @param auth
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
            throws IOException, ServletException {
        log.info("用户登陆成功");
        // 组装JWT
        SysUser selfUserEntity = (SysUser) authentication.getPrincipal();
        log.info("组装的用户实体类 selfUserEntity ===>{}", selfUserEntity.toString());
        response.sendRedirect("about");
    }

}
